﻿using Kinlo.Entitys;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using XingLucifer.IBase.Enums;

namespace UIWindows.Tools.Converter
{
    public class ItemBackgroundConverter : IValueConverter
    {
        private static ItemBackgroundConverter _instance;

        public static ItemBackgroundConverter Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new ItemBackgroundConverter();
                }
                return _instance;
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ListViewItem listViewItem = (ListViewItem)value;
            if (listViewItem == null)
            {
                return Brushes.Transparent;
            }
            var barcode = listViewItem.DataContext as Models.Homes.MessageBeforeScanCodeModel;
            if (barcode != null) 
            {
                return (barcode.Result <= ResultTypes.合格) ? Brushes.Transparent : new SolidColorBrush(Color.FromArgb(0xFF, 0xF3, 0x51, 0x51));
            }
            var weigth = listViewItem.DataContext as Models.Homes.MessageBeforeWeighingModel;
            if (weigth != null)
            {
                return (weigth.Result <= ResultTypes.合格) ? Brushes.Transparent : new SolidColorBrush(Color.FromArgb(0xFF, 0xF3, 0x51, 0x51));
            }
            var model = listViewItem.DataContext as ProductionData;
            if (model == null)
            { return Brushes.Transparent; }
            return (model.ResultTotal <= ResultTypes.合格) ? Brushes.Transparent : new SolidColorBrush(Color.FromArgb(0xFF, 0xF3, 0x51, 0x51));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
